package com.moli.iov.handle.real.mq.kafka;

import com.moli.iov.handle.real.biz.RealTimeInfoHandler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.listener.BatchAcknowledgingMessageListener;
import org.springframework.kafka.support.Acknowledgment;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@Data
public class RealTimeBatchConsumer implements BatchAcknowledgingMessageListener<String, Object> {

    @Resource
    RealTimeInfoHandler handler;

    /**
     * 消费上报数据
     * @param data
     * @param acknowledgment
     */
    @Override
    public void onMessage(List<ConsumerRecord<String, Object>> data, Acknowledgment acknowledgment) {
        //处理上报数据
        handler.handle(data);
        //提交offset
        acknowledgment.acknowledge();
    }
}
